const descriptor = {
  name: {
    type: 'string',
    required: true,
  },
  choices: {
    type: 'array',
    required: true,
    message: 'choices至少有一个',
    min: 1,
    defaultField: {
      type: 'object',
      required: true,
      fields: {
        name: {
          type: 'string',
          required: true,
        },
        value: {
          type: 'string',
          required: true,
        },
      },
    },
  },
  deployList: {
    type: 'array',
    required: true,
    message: 'deployList至少有一个',
    min: 1,
    defaultField: {
      type: 'object',
      required: true,
      fields: {
        VALUE: {
          type: 'string',
          required: true,
        },
        SERVER_PATH: {
          type: 'string',
          message: 'SERVER_PATH必须是ip地址格式',
          validator(rules, value, cb, source) {
            const reg = /^([1-9]|[1-9]\d|1\d\d|2[01]\d|22[0-3])(\.([1-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])){3}$/
            if ([3, 4].includes(source.RUN_MODEL)) {
              return reg.test(value)
            } else {
              cb()
            }
          },
        },
        SSH_USER: {
          type: 'string',
          validator(rules, value, cb, source) {
            if ([3, 4].includes(source.RUN_MODEL) && value.trim() === '') {
              cb(new Error('SSH_USER必须输入'))
            } else {
              cb()
            }
          },
        },
        PASSWORD: {
          type: 'string',
          validator(rules, value, cb, source) {
            if ([3, 4].includes(source.RUN_MODEL) && value.trim() === '') {
              cb(new Error('PASSWORD必须输入'))
            } else {
              cb()
            }
          },
        },
        PATH: {
          type: 'string',
          validator(rules, value, cb, source) {
            if ([3, 4].includes(source.RUN_MODEL) && value.trim() === '') {
              cb(new Error('PATH必须输入'))
            } else {
              cb()
            }
          },
        },
        SCRIPT: {
          type: 'string',
          validator(rules, value, cb, source) {
            if (source.RUN_MODEL !== 4 && value.trim() === '') {
              cb(new Error('SCRIPT必须输入'))
            } else {
              cb()
            }
          },
        },
        ASSETS_PATH: {
          type: 'string',
          validator(rules, value, cb, source) {
            if (source.RUN_MODEL !== 4 && value.trim() === '') {
              cb(new Error('ASSETS_PATH必须输入'))
            } else {
              cb()
            }
          },
        },
        SERVER_CMD: {
          type: 'any',
          // defaultField: {
          //   type: 'string'
          // }
        },
        RUN_MODEL: {
          type: ['string', 'number'],
          message: 'RUN_MODEL必须是1,2,3,4中其中一个',
          validator(...args) {
            const [, value] = args
            return [1, 2, 3, 4].includes(Number(value))
          },
        },
      },
    },
  },
}

module.exports = descriptor
